package com.example.projecth.project3;

import com.example.projecth.R;

import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

	private Fragment[] fragments;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bjhactivity_main);

		fragments = new Fragment[3];
		fragments[0] = new ChinUp();
		fragments[1] = new StopWatchFragment();
		fragments[2] = new TimerFragment();
		 
		
	
		ActionBar bar = getActionBar();
		
		bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		bar.addTab(bar.newTab().setText("철봉운동").setTabListener(listener));
		bar.addTab(bar.newTab().setText("스톱워치").setTabListener(listener));
		bar.addTab(bar.newTab().setText("타이머").setTabListener(listener));

		bar.selectTab(bar.getTabAt(0));
		
		

	}

	private TabListener listener = new TabListener() {

		@Override
		public void onTabUnselected(Tab tab, FragmentTransaction ft) {

		}

		@Override
		public void onTabSelected(Tab tab, FragmentTransaction ft) {
			ft.replace(R.id.fragment_container, fragments[tab.getPosition()]);
		}

		@Override
		public void onTabReselected(Tab tab, FragmentTransaction ft) {

		}
	};
	
//	public void changeView (View view) {
//		int tag = Integer.parseInt(((Button)view).getTag().toString());
//		changeFragment(tag);
//		((View)view.getParent()).invalidate();
//		
//	}
//	
//	public void changeFragment(int tag) {
//		FragmentManager manager = getFragmentManager();
//		FragmentTransaction tran = manager.beginTransaction();
//		tran.replace(R.id.fragment_container2, fragments2[tag]);
//		tran.commit();
//		
//	}

}
